package cn.wolfcode.web.interceptor;

import cn.wolfcode.ssm.domain.Employee;
import cn.wolfcode.ssm.util.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // Employee employee = (Employee) request.getSession().getAttribute("EMPLOYEE_IN_SESSION");
        // 判断有没有session 有就放行  没有就返回登陆页面
        Employee employee = UserContext.getCurrentUser();
        if (employee == null){
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
